package com.yanduo.tags

import org.apache.commons.lang3.StringUtils
import org.apache.spark.sql.Row

/**
  * APP标签
  *
  * @author Gerry chan
  * 2020/5/5 11:46
  * @version 1.0
  */
object Tags4App extends Tags {
  override def makeTags(args: Any*): Map[String, Int] = {
    var map = Map[String, Int]()
    //row 对象
    val row = args(0).asInstanceOf[Row]

    //字典对象,转为Map
    val appDict = args(1).asInstanceOf[Map[String, String]]

    val appId = row.getAs[String]("appid")
    val appName = row.getAs[String]("appname")

    if(StringUtils.isNotEmpty(appName)) {
      appDict.contains(appId) match {
        case true => map += "APP" + appDict->1
      }
    }

    //渠道标签
    val chanelId = row.getAs[Int]("adplatformproviderid")
    if (chanelId >0) map +=(("Cn"+chanelId,1))

    map
  }
}
